package at.socialconference.web.client.ui;

import at.socialconference.inter.model.Place;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

public class ShowPlacePopup extends PopupPanel {
	public ShowPlacePopup(final Place p) {
		this.setGlassEnabled(true);
		VerticalPanel vp = new VerticalPanel();
		FlexTable details = new FlexTable();
		this.add(vp);
		vp.add(details);
		int i = -1;
		details.setWidget(++i, 0, new Label("Place:"));
		details.setWidget(i, 1, new Label(p.getName()));

		details.setWidget(++i, 0, new Label("Description:"));
		details.setWidget(i, 1, new Label(p.getDescription()));

		details.setWidget(++i, 0, new Label("Latitude:"));
		details.setWidget(i, 1, new Label(p.getLatitude().toString()));

		details.setWidget(++i, 0, new Label("Longitude:"));
		details.setWidget(i, 1, new Label(p.getLongitude().toString()));

		if (p.getLatitude() != null && p.getLatitude() != 0.0 && p.getLongitude() != null && p.getLongitude() != 0.0) {

			Button btn = new Button("Show on map");
			btn.addClickHandler(new ClickHandler() {
				@Override
				public void onClick(ClickEvent event) {
					new MapPopUp(p);
				}
			});

			details.setWidget(++i, 0, new Label("Map:"));
			details.setWidget(i, 1, btn);
		}

		this.center();
		HorizontalPanel hp = new HorizontalPanel();
		Button btnBack = new Button("Back");
		btnBack.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				ShowPlacePopup.this.hide();
			}
		});
		hp.add(btnBack);
		hp.setCellHorizontalAlignment(btnBack, HasHorizontalAlignment.ALIGN_CENTER);
		vp.add(hp);
	}
}
